//    Copyright (C) Kherty.  All rights reserved.
using System.Collections.ObjectModel;
using OpenLS.Core.Serialization;

namespace OpenLS.Chart
{
    public abstract class PieChartBase : ChartBase, IDataLabelsOwner
    {
        private ObservableCollection<PieSeries> _series;
        private DataLabels dLbls;

        private bool varyColors = true;

        public DataLabels DataLabels
        {
            get { return dLbls; }
            set { dLbls = value; notifyPropertyChanged("DataLabels"); }
        }

        public bool VaryColors
        {
            get { return varyColors; }
            set
            {
                varyColors = value;
                notifyPropertyChanged("VaryColors");
            }
        }

        public ObservableCollection<PieSeries> Series
        {
            get
            {
                if (_series == null)
                    _series = CreateSeriesCollection<PieSeries>();
                return _series;
            }
        }

        #region IChartWithDisplayInformation Members

        #endregion

        protected void ReadXmlBase(ReadContext c)
        {
            varyColors = ChartHelper.ReadVaryColors(c);
            Series.Clear();

            while (c.ReaderLocalName == "ser")
            {
                var s = new PieSeries();
                s.ReadXmlCore(c);
                Series.Add(s);
            }
            DataLabels = c.ReadOptionalElement<DataLabels>(DataLabels.xmlName);
        }


        protected void WriteXmlBase(WriteContext c)
        {
            ChartHelper.WriteVaryColors(c, VaryColors);
            foreach (PieSeries s in Series)
            {
                s.WriteXmlCore(c);
            }
            c.WriteOptionalElement(DataLabels);
        }
    }
}